<template>
  <div>
    <!-- 头部导航 -->
    <van-nav-bar
      :title="!comment.reply_count ? '暂无回复': comment.reply_count + '条回复'"
      @click-left="onClickLeft"
    >
      <van-icon slot="left" name="cross" />
    </van-nav-bar>

    <div class="center-scroll">
      <CommentItem :comment="comment"/>

      <van-cell title="全部回复" />

      <CommentList :list="list" type="c" :source="comment.com_id" />
    </div>

    <div class="post-warp">
      <van-button @click="showReplyPost = true" round>评论</van-button>
    </div>

    <van-popup v-model="showReplyPost" position="bottom">
      <CommentPost @on-post-success="onPostSuccess" :target="comment.com_id" :art_id="articleId"/>
    </van-popup>
  </div>
</template>

<script>
import CommentItem from '@/components/comment-item.vue'
import CommentList from './article-comment.vue'
import CommentPost from './comment-post.vue'
export default {
  data() {
    return {
      list: [],
      showReplyPost: false
    }
  },

  components: {
    CommentItem,
    CommentList,
    CommentPost
  },

  props: {
    comment: {
      type: Object,
      required: true
    },
    articleId: {
      type: String,
      required: true
    }
  },

  created() {

  },

  methods: {
    onClickLeft() {
      this.$emit('click-left')
    },
    onPostSuccess(data) {
      this.list.unshift(data)
      this.showReplyPost = false
    }
  }
}
</script>

<style scoped lang='less'>
.center-scroll {
  position: absolute;
  top: 92px;
  bottom: 88px;
  overflow-y: scroll;
  width: 100%;
}
.post-warp {
  width: 100%;
  height: 100px;
  position: fixed;
  bottom: 0;
  border-top: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: hotpink;
  .van-button {
    width: 640px;
    height: 80px;
  }
}
</style>
